package net.shopxx.dao.impl;

import net.shopxx.bean.Pager;
import net.shopxx.dao.OrderItemDao;
import net.shopxx.entity.Member;
import net.shopxx.entity.OrderItem;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * Dao实现类 - 订单项
 */

@Repository
public class OrderItemDaoImpl extends BaseDaoImpl<OrderItem, String> implements
		OrderItemDao {

	@SuppressWarnings("unchecked")
	@Override
	public Pager getOrderItemList(Member member,Pager pager) {
		if(pager==null)
		{
			pager = new Pager();
		}
		Integer pageNumber = pager.getPageNumber();
		Integer pageSize = pager.getPageSize();
		String hql = "select oi from OrderItem as oi inner join oi.productitem as pi with pi.member.id=?";
		Query query = getSession().createQuery(hql).setParameter(0, member.getId());
		pager.setTotalCount(query.list().size());
		query.setFirstResult((pageNumber - 1) * pageSize);
		query.setMaxResults(pageSize);
		pager.setList(query.list());
		return pager;
	}

}